With the development of communication technologies, more and more application programs are integrated on a terminal, for example, MSN, QQ, and other instant messenger (IM) application programs. In a process of running the foregoing IM application programs, when no data is transmitted, a corresponding client sends a heartbeat (HB) message to a server periodically so as to inform, through a device at the network side, the server of its own online state and maintain a session connection.
A heartbeat period depends on configurations of a network traversed by the heartbeat. If the heartbeat period is too short, the power consumption of the terminal is seriously affected, the network traffic is increased, and the performance of each network element in the network and a system is affected. However, if the heartbeat period is too long, it may exceed a timeout interval set by some network elements in the network to detect when no data is transmitted, thereby causing the release of a session connection and a failure to achieve a purpose of connection keep-alive. For example, for a firewall or network address translation (NAT) device deployed in the network, the session-hold time of the firewall is set to be relatively short to ensure the security of an internal network, and the transmission control protocol (TCP) session-hold time is generally 20 to 30 minutes. If no data is transmitted in the session, the session information is forcibly released after the time expires, and in this way, all subsequent messages are discarded. To avoid the occurrence of the foregoing case, in the prior art, the terminal adjusts the heartbeat period gradually to gradually approach an optimal heartbeat period that the network can support so as to adapt to different network configuration situations automatically.
In the prior art, however, the terminal needs to perform multiple heartbeat message interactions with the server to adjust the heartbeat period gradually, which causes power consumption of the terminal and increases signaling loads of the device at the network side at the same time, thereby affecting the system performance.